package com.wgchao.authmanager.application.dispatch;

import com.wgchao.authmanager.application.vo.AdministratorVo;
import com.wgchao.authmanager.application.vo.AuthoInfoVo;
import com.wgchao.authmanager.infrastructure.resp.BackResult;
import com.wgchao.authmanager.query.AuthoQuery;
import com.wgchao.authmanager.query.UserInfoQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: UserDispatchService
 * @author: wgchao
 * @createTime: 2020/5/18 2:26 PM
 * @Description: TODO
 */
@RestController
@RequestMapping("/aum/dispatch/user")
@Api(value = "/aum/dispatch/user", description = "账户业务，内部服务调用")
public class UserDispatchService {
    @Autowired
    private AuthoQuery authoQuery;
    @Autowired
    private UserInfoQuery userInfoQuery;

    @GetMapping("/autho/all/{uname}/{projectIdentify}")
    @ApiOperation(value = "获取账户在项目下所有菜单权限", notes = "无需身份验证")
    public BackResult<List<AuthoInfoVo>> findAllAuthosOfAdmin(@ApiParam(value = "账户名（url参数）", name = "uname", required = true)
                                                              @PathVariable String uname,
                                                              @ApiParam(value = "项目标识（url参数）", name = "projectIdentify", required = true)
                                                              @PathVariable String projectIdentify){
        List<AuthoInfoVo> authoInfoVos = authoQuery.searchAllAuthosOfAdmin(uname, projectIdentify);
        return BackResult.success().setData(authoInfoVos);
    }

    @GetMapping("/base/{uname}")
    @ApiOperation(value = "获取账户基本信息", notes = "无需身份验证")
    public BackResult<AdministratorVo> searchAdminInfo(@ApiParam(value = "账户名（url参数）", name = "uname", required = true)
                                                       @PathVariable String uname){
        AdministratorVo administratorVo = userInfoQuery.searchAdminInfo(uname);
        return BackResult.success().setData(administratorVo);
    }
}
